﻿package
{
	import foli.Gallery;
	import foli.Board;
	
	import flash.display.Sprite;
	import flash.events.Event;

	import org.papervision3d.view.Viewport3D;
	import org.papervision3d.scenes.Scene3D;
	import org.papervision3d.cameras.Camera3D;
	import org.papervision3d.cameras.FreeCamera3D;
	import org.papervision3d.materials.ColorMaterial;
	import org.papervision3d.objects.primitives.Plane;
	import org.papervision3d.render.BasicRenderEngine;

	public class Foli extends Sprite
	{
		private var viewport:Viewport3D;
		private var scene:Scene3D;
		private var camera:FreeCamera3D;
		private var renderer:BasicRenderEngine;

		public function Foli():void
		{
			viewport = new Viewport3D(800, 600, false, true);
			addChild(viewport);

			//instantiates a Scene3D instance
			scene = new Scene3D();

			//instantiates a Camera3D instance
			camera = new FreeCamera3D();			

			//renderer draws the scene to the stage
			renderer = new BasicRenderEngine();

			//set up enterFrame event
			addEventListener(Event.ENTER_FRAME, onEnterFrame);
			
			init();			
		}
		//define enterFrame Method, render the Scene and animate the primitives
		public function onEnterFrame(e:Event):void
		{
			update();
			render();
		}
		public function render():void
		{
			renderer.renderScene(scene, camera, viewport);
		}
		public function update():void
		{
			// update cam
			camera.zoom = 15;
			camera.focus = 30;
			camera.rotationX = -(viewport.mouseY - stage.height / 2.0) / 4.0;  
			camera.rotationY = (viewport.mouseX - stage.width / 2.0) / 4.0;			
		}
		
		public function init():void
		{			
			// create Gallery to store data
			var g: Gallery = new Gallery("sascha.seewald");
			
			// create graphical representation 
			var b: Board = new Board(g);
			
			// add grapic object to our scene
			scene.addChild(b);			
						
			// load albums
			g.loadAlbumList();
		}		
		
	}
}